package com.king.hrmsdev.controller;

import com.alibaba.fastjson.JSONObject;
import com.king.hrmsdev.pojo.VSalaryinfo;
import com.king.hrmsdev.service.SalaryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther:SnakeKing
 * @Date: 2019-09-22
 * @Description: com.king.hrmsdev.controller
 * @version:1.0
 */
@RestController
public class SalaryController {

    @Resource
    private SalaryService salaryService;


    //
    @RequestMapping(value = "/FindallSalary", method = RequestMethod.POST)
    //查询所有数据
    public JSONObject FindallSalary() {
        List<VSalaryinfo> lists = salaryService.QuaryAllSalary();
        JSONObject result = new JSONObject();
        result.put("msg", "ok");
        result.put("method", "FindallSalary");
        result.put("lists", lists);
        return result;
    }

    //
    @RequestMapping(value = "/AddSalary", method = RequestMethod.POST)
    //向数据库添加薪水纪录
    public void AddSalary() {
        salaryService.AddSalary();
    }


    @RequestMapping(value = "/QuarySalaryList", method = RequestMethod.POST)
    public JSONObject QuarySalaryList(@RequestParam(value = "job_id", required = false, defaultValue = "") String job_id,
                                      @RequestParam(value = "ename", required = false, defaultValue = "") String ename) {

        int id = 0;
        String name = "";
        if (!(job_id.equals("") || job_id.equals(null))) {
            id = Integer.valueOf(job_id);
            System.out.println(id);
        }
        if (!(ename.equals("") || ename.equals(null))) {
            name = ename;
            System.out.println(name);
        }
        List<VSalaryinfo> lists = salaryService.QuarySalary(id, name, null);
        System.out.println(lists);
        JSONObject result = new JSONObject();
        result.put("msg", "ok");
        result.put("method", "QuarySalaryList");
        result.put("lists", lists);
        return result;
    }
}
